<template>
  <div class="index">
    <el-container>
      <el-header>
        <img class="img-h" src="../assets/images/index/u191.png" alt="" />
        <div class="a-st">
          <a
            v-for="(item, index) in getInfo"
            :key="index"
            :class="{ 'a-css': true, active: activeIndex === index }"
            href="javascript:;"
            @click="toHandler(item.title, index)"
            >{{ item.title }}</a
          >
        </div>
        <ul style="line-height:50px" v-show="isShow" class="ulf">
          <li>
            <a href="#"><img src="../assets/images/index/u1372.png" alt=""/></a>
          </li>
          <li>
            <a class="flex-a" href="#">
              <img src="../assets/images/index/u1374.png" alt="" />
              <img src="../assets/images/index/u1374.png" alt="" />
              <img src="../assets/images/index/u1374.png" alt="" />
            </a>
          </li>
          <li>
            <a href="#">
              <img src="../assets/images/index/u1377.png" alt="" />
            </a>
          </li>
          <li @click="loginoutClick">
            <a href="#"><img src="../assets/images/index/u1380.png" alt=""/></a>
          </li>
        </ul>
        <div v-show="isShow" class="img-div" style="line-height:50px">
          <img src="../assets/logo.png" alt="" width="30px" class="logo-img" />
          <span>{{ usn }}</span>
          <div class="div-po">
            <div class="u-header">账户信息:</div>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-col :span="24" style="height:100%;background:#545c64">
            <!-- <el-menu
              :default-active="saveParam"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b"
              unique-opened
              :collapse="isCollapse"
              :collapse-transition="false"
              router
            >
              <el-submenu
                v-for="(item, index) in getAsides"
                :key="index"
                :index="'/' + item.path"
              > -->
            <!-- 一级菜单 -->
            <!-- <template slot="title">
                  <span>{{ item.title }}</span>
                </template>
                <el-menu-item-group>
                   二级菜单 -->
            <!-- <el-menu-item
                    :index="'/' + v.path"
                    v-for="v in item.children"
                    :key="v.path"
                    ><template slot="title">
                      <span>{{ v.title }}</span>
                    </template></el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
            </el-menu> -->
            <el-menu
              default-active="/system-setup?name=系统设置"
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose"
              theme="dark"
              router
            >
              <el-submenu
                v-for="(item, index) in getAsides"
                :key="index"
                :index="'/' + item.path"
              >
                <template slot="title">{{ item.title }}</template>
                <el-menu-item
                  :index="'/' + v.path + '?name=' + v.title"
                  v-for="v in item.children"
                  :key="v.path"
                  >{{ v.title }}</el-menu-item
                >
              </el-submenu>
            </el-menu>
          </el-col></el-aside
        >
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
    <el-dialog title="确认退出登录？" :visible.sync="longQueren" width="30%">
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleCloseQuexiao">取 消</el-button>
        <el-button type="primary" @click="hangleQueding">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      getInfo: [],
      getAsides: [],
      activeIndex: 0,
      usn: '',
      isShow: false,
      saveParam: '',
      longQueren: false
    }
  },
  methods: {
    hangleQueding() {
      window.sessionStorage.removeItem('token')
      this.$router.push('/login')
    },
    handleCloseQuexiao() {
      this.longQueren = false
    },
    loginoutClick() {
      this.longQueren = true
    },
    async getInfos() {
      this.usn = JSON.parse(window.sessionStorage.getItem('username'))
      console.log(this.usn)
      const { data: res } = await this.$http.get('/index/information')
      this.getInfo = res.data
      this.getAsides = this.getInfo[0].children
      this.isShow = true
      console.log(this.getInfo)
    },
    toHandler(t, i) {
      this.activeIndex = i
      this.getInfo.forEach(item => {
        if (item.title === t) {
          this.getAsides = item.children
        }
      })
      console.log(this.getAsides)
    },
    handleOpen() {
      console.log(1)
    },
    handleClose() {
      console.log('guanbii')
    },
    toggletab() {
      this.isCollapse = !this.isCollapse
    }
  },
  created() {
    this.getInfos()
  },
  updated() {
    this.saveParam = window.sessionStorage.getItem('path')
    console.log(this.saveParam)
  }
}
</script>

<style lang="less">
.el-submenu__title {
  color: #fff !important;
}
.el-menu-item {
  color: #fff !important;
}
.el-menu {
  background: #545c64 !important;
}
.el-menu-item {
  padding-right: 10px !important;
}
.flex-a {
  display: flex;
  flex-flow: column;
  margin-top: 20px;
  img {
    margin-top: 1px;
  }
}
.img-h {
  width: 74px;
  height: 30px;
  float: left;
  margin-top: 10px;
  margin-right: 20px;
}
.index {
  height: 100%;
  .el-container {
    height: 100%;
  }
}

.el-header {
  background-color: #595e6c;
  color: #333;
  padding: 0 10px !important;
  text-align: center;
  height: 50px !important;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;

  // text-align: center;
  // line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-menu-vertical-demo {
  border-right: 1px !important;
}
.a-css {
  float: left;
  line-height: 50px;
  padding: 0 20px;
  font-size: 12px;
  color: #fff;
  text-decoration: none;
}
.active {
  color: #999;
}

.img-div {
  z-index: 999;
  float: right;
  cursor: pointer;
  position: relative;
  .logo-img {
    vertical-align: middle;
    background: #fff;
    border: 1px solid #fff;
    border-radius: 50%;
    margin-right: 10px;
  }
  span {
    color: #fff;
    font-size: 12px;
  }
  .div-po {
    width: 420px;
    height: 235px;
    position: absolute;
    right: -200%;
    background: #000;
    display: none;
  }
}

.img-div:hover .div-po {
  display: block;
}
.a-st {
  width: 580px;
  float: left;
}
.ulf {
  float: right;
  li {
    float: left;
    margin: 0 10px;
    list-style: none;
    img {
      vertical-align: middle;
    }
  }
}
</style>
